﻿using System;
using System.Web.Mail;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Collections.Generic;
using MLY;
using MLY.Dal;
using MLY.Bll;
using System.IO;


namespace MLY.LTR
{
    public partial class MyAlerts : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (clsUser.CurrentUserRoleId < 0)
            {
                Response.RedirectTo("/LTR/Login.aspx?ReturnTo=" + Request.Url.ToString());
            }

            if (!IsPostBack)
            {
                UserAlertsDataSource.SelectParameters.Add("UserId", SessParam.UserId.ToString());
                UserAlertsDataSource.SelectParameters.Add("AlertSetList", "1");
            }
            if (AlertsGrid.Rows.Count > 0)
            {
                // for tablesorter
                AlertsGrid.UseAccessibleHeader = true;
                AlertsGrid.HeaderRow.TableSection = TableRowSection.TableHeader;
            }

        }

        protected void DeleteSelected(object sender, EventArgs e)
        {
            using (SqlConnection conn = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["MLYConnectionString"].ConnectionString))
            {
                SqlCommand cmd = new SqlCommand("SCCover_CloseRowMarking", conn);
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Parameters.Add("MarkingId", SqlDbType.Int);

                foreach (GridViewRow r in AlertsGrid.Rows)
                {
                    try
                    {
                        if ((r.RowType == DataControlRowType.DataRow) &&
                            ((r.FindControl("SelectBox") as CheckBox).Checked))
                        {
                            cmd.Parameters["MarkingId"].Value = (r.FindControl("MarkingIdHiddenField") as HiddenField).Value;
                            try
                            {
                                conn.Open();
                                cmd.ExecuteNonQuery();
                            }
                            catch { }
                            finally
                            {
                                conn.Close();
                            }
                        }
                    }
                    catch { }

                }
            }
            AlertsGrid.DataBind();
        }
    }
}
